import 'package:flutter/material.dart';

//import page
import 'package:state_flutter/pages/Index/index.dart';
import 'package:state_flutter/pages/Home/home.dart';
import 'package:state_flutter/pages/Order/order.dart';
import 'package:state_flutter/pages/UserInfo/userinfo.dart';

class Tabs extends StatefulWidget {
  Tabs({Key key}) : super(key: key);

  @override
  _TabsState createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int current = 0;
  List<Widget> list = [];

  @override
  void initState() { 
    this.list = [
      IndexPage(),
      OrderPage(),
      HomePage(),
    ];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: this.list[this.current],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this.current,
        onTap: (int index){
          setState(() {
            this.current = index;
          });
        },
        unselectedItemColor: Colors.black38,
        type: BottomNavigationBarType.fixed,
        fixedColor: Color.fromRGBO(20, 100, 160, 1),
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            title: Text('首页')
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.menu),
            title: Text('订单')
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.my_location),
            title: Text('我的')
          )
        ],
      ),
      drawer: UserInfo(),
    );
  }
}


/*
 * floatingActionButton 浮动按钮
 */
class FloatingTabs extends StatefulWidget {
  FloatingTabs({Key key}) : super(key: key);

  @override
  _FloatingTabsState createState() => _FloatingTabsState();
}

class _FloatingTabsState extends State<FloatingTabs> {
  int current = 0;
  List<Widget> list = [];

  @override
  void initState() { 
    this.list = [
      IndexPage(),
      OrderPage(),
      HomePage(),
    ];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: this.list[this.current],
      floatingActionButton: Container(
        width: 60.0,
        height: 60.0,
        padding: EdgeInsets.all(7),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(30),
        ),
        child: FloatingActionButton(
          child: Icon(Icons.add),
          elevation: 0,
          onPressed: (){
            setState(() {
              this.current = 1;
            });
          },
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this.current,
        onTap: (int index){
          setState(() {
            this.current = index;
          });
        },
        backgroundColor: Colors.white,
        unselectedItemColor: Colors.black38,
        type: BottomNavigationBarType.fixed,
        fixedColor: Color.fromRGBO(20, 100, 160, 1),
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            title: Text('首页')
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.menu),
            title: Text('订单')
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.my_location),
            title: Text('我的')
          )
        ],
      ),
      drawer: UserInfo(),
    );
  }
}


/*
 * 自定义底部导航 
 * BottomAppBar
 */
class CustomTabs extends StatefulWidget {
  CustomTabs({Key key}) : super(key: key);

  @override
  _CustomTabsState createState() => _CustomTabsState();
}

class _CustomTabsState extends State<CustomTabs> {
  
  int current = 0;
  List<Widget> list = [];

  @override
  void initState() { 
    this.list = [
      IndexPage(),
      OrderPage(),
      HomePage(),
    ];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: this.list[this.current],
      floatingActionButton: FloatingActionButton(
        onPressed: (){
          setState(() {
            this.current = 1;
          });
        },
        child: Icon(
          Icons.add,
          color: Colors.white,
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: BottomAppBar(
        color: Colors.lightBlue,
        shape: CircularNotchedRectangle(),
        child: Row(
          //里面可以设置大部分Widgrt,让我们随心所欲的设计Tabs
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          mainAxisSize: MainAxisSize.max,
          children: <Widget>[
            IconButton(
              icon: Icon(
                Icons.home,
                color: Colors.white,
              ),
              color: Colors.white,
              onPressed: (){
                setState(() {
                  this.current = 0;
                });
              },
            ),
            IconButton(
              icon: Icon(
                Icons.my_location,
                color: Colors.white,
              ),
              color: Colors.white,
              onPressed: (){
                setState(() {
                  this.current = 2;
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}